from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from options import options


class Login():
    def __init__(self, driver):
        self.driver = driver

    def login(self):
        self.driver.find_element(By.ID, 'ls_username').clear()
        self.driver.find_element(By.ID, 'ls_username').send_keys('admin')
        self.driver.find_element(By.ID, 'ls_password').clear()
        self.driver.find_element(By.ID, 'ls_password').send_keys('sa')
        sleep(3)
        self.driver.find_element(By.XPATH, '//*[@id="lsform"]/div/div/table/tbody/tr[2]/td[3]/button/em').click()
        sleep(3)

    def logout(self):
        self.driver.find_element(By.LINK_TEXT, '退出').click()
        sleep(3)


if __name__ == '__main__':
    url = r'http://172.16.36.121/upload/'
    driver = webdriver.Chrome(options=options)
    driver.get(url)

    login = Login(driver)
    login.login()
    login.logout()

    driver.quit()
